Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add router and ensembler webhook #395

Merged
merged 20 commits into from
Nov 11, 2024
Merged

feat: add router and ensembler webhook #395

merged 20 commits into from
Nov 11, 2024

Conversation

bayu-aditya
Copy link
Collaborator

@bayu-aditya bayu-aditya commented Oct 9, 2024

Context

This PR to adding webhooks for Router and Ensembler for this action and event type.

  • Router Webhook
    • Creating Router (OnRouterCreated)
    • Updating Router (OnRouterUpdated)
    • Deleting Router (OnRouterDeleted)
  • Router Deployment Webhook
    • Deploying Router (OnRouterDeployed)
    • Undeploying Router (OnRouterUndeployed)
  • Ensembler Webhook
    • Creating Ensembler (OnEnsemblerCreated)
    • Updating Ensembler (OnEnsemblerUpdated)
    • Deleting Ensembler (OnEnsemblerDeleted)

For router, Turing will send webhook event with this body payload

{
  "event_type": "OnRouterCreated",

  // models.Router
  "router": {
    "id": 123,
    "created_at": "string",
    "updated_at": "string",
    "project_id": 456,
    "environment_name": "string",
    "name": "string",
    "status": "string",
    "endpoint": "string",
    "config": {},
    "monitoring_url": "string"
  }
}

Then for router deployment, Turing will send webhook event with this body payload

{
  "event_type": "OnRouterDeployed",
  "project_id": 456,

  // models.RouterVersion
  "router_version": {
    "id": 123,
    "created_at": "string",
    "updated_at": "string",

    "router": {},
    "version": 123,
    "status": "deployed"
  }
}

And for ensembler, Turing will send webhook event with this body payload

{
  "event_type": "OnEnsemblerCreated",

  // models.GenericEnsembler or models.PyFuncEnsembler
  "ensembler": { 
    "id": 123,
    "created_at": "string",
    "updated_at": "string",
    "project_id": 456,
    "type": "string",
    "name": "string"
  }
}

Changes

  • Create webhook client package and unittest
  • Add webhook client in BaseController
  • Invoke webhook in this HTTP handler functions:
    • POST /projects/{project_id}/routers
    • PUT /projects/{project_id}/routers/{router_id}
    • DELETE /projects/{project_id}/routers/{router_id}
    • POST /projects/{project_id}/routers/{router_id}/deploy
    • POST /projects/{project_id}/routers/{router_id}/undeploy
    • POST /projects/{project_id}/ensemblers
    • PUT /projects/{project_id}/ensemblers/{ensembler_id}
    • DELETE /projects/{project_id}/ensemblers/{ensembler_id}

api/turing/api/ensemblers_api.go Outdated Show resolved Hide resolved
api/turing/webhook/webhook.go Outdated Show resolved Hide resolved
api/turing/webhook/webhook.go Outdated Show resolved Hide resolved
api/turing/api/ensemblers_api.go Outdated Show resolved Hide resolved
api/turing/api/routers_api.go Outdated Show resolved Hide resolved
api/turing/api/routers_api.go Outdated Show resolved Hide resolved
Copy link
Contributor

@deadlycoconuts deadlycoconuts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the PR! I've left a couple of tiny comments here and there but the most important one is the one about calling the webhooks whenever a router is updated, because that involves 2 steps, the deployment of a new router version and subsequently, the undeployment of the previous router version.

Another (equally tricky) change you might've left out is to add webhook calls to the 'DeployRouterVersion' method. This is similarly (or even more) confusing because there are two possible scenarios here - 1) there's just a simple deployment of a specific router version (no undeployment involved) and 2) there's a deployment of the specified router version + the undeployment of an existing deployed router version. Scenario 1 happens when there are no existing router versions deployed but scenario 2 happens when another router version was already deployed when that API endpoint gets called. You might need to poke a little more to find out some way to determine if you need 1 additional webhook call for the undeployment event for this API endpoint.

api/go.mod Outdated Show resolved Hide resolved
api/go.mod Outdated Show resolved Hide resolved
api/turing/webhook/webhook.go Outdated Show resolved Hide resolved
api/turing/webhook/webhook.go Outdated Show resolved Hide resolved
api/turing/api/ensemblers_api.go Show resolved Hide resolved
api/turing/api/routers_api.go Outdated Show resolved Hide resolved
api/turing/api/routers_api.go Outdated Show resolved Hide resolved
api/turing/webhook/webhook.go Show resolved Hide resolved
api/turing/webhook/request.go Outdated Show resolved Hide resolved
Copy link
Contributor

@bthari bthari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and thank you so much for the changes @deadlycoconuts!

@deadlycoconuts
Copy link
Contributor

Thanks a lot for looking at this PR again! Thanks a lot @bayu-aditya also for most of the work! :D I'll merge this PR now!

@deadlycoconuts
Copy link
Contributor

deadlycoconuts commented Nov 11, 2024

Damn I had to approve this PR myself (to allow the merge button to appear) even though I have pushed changes to it and other people have approved it. It's probably because I selected the 'request changes' option when reviewing this PR and I need to be the one approving if I select that option 😑

@deadlycoconuts deadlycoconuts merged commit fced7db into main Nov 11, 2024
13 checks passed
@deadlycoconuts deadlycoconuts deleted the bayu/webhook branch November 11, 2024 04:39
@deadlycoconuts deadlycoconuts added the enhancement New feature or request label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants